import React, { useEffect } from "react";
import { connect } from "react-redux";
import action from "./store/Actions"
import router from "./router";
import RouterView from "./router/RouterView/RouterView";
import RouterLink from "./router/RouterLink/RouterLink";
import {withRouter} from 'react-router-dom';
import 'antd/dist/antd.css';
import "./App.less";
function App(props) {
  useEffect(() => {
    let token = localStorage.getItem('token')
    if (!token) {
      if (props.location.pathname != '/login') {
        props.history.push('/Login')
      }
    }else{
      
      // if (props.location.pathname == '/login'||props.location.pathname == '/Login') {
        
        let tokens=JSON.parse(token)
        console.log(tokens);
        if(tokens.type=='0'){
          props.history.push('/Home')
        }else if(tokens.type=='1'){
          props.history.push('/Marketing')
          
        }else if(tokens.type=='2'){
          props.history.push('/Educational')
        }else if(tokens.type=='3'){
          props.history.push('/Finance')
        }
       
      // }
    }
  }, []);

  useEffect(()=>{
    const { getVersion } = props;
    getVersion();
  },[]);
  return (
        <div className="App">
          <div className="header">
            <div className="logo">
              <img src={ props.administratorReducer.version.logo } alt="" />
              <span>{ props.administratorReducer.version.title }</span>
            </div>
            <div className="useRoot">
              
            </div>
          </div>
          <div className="main">
            <div className="Aside">
              <RouterLink router={router}></RouterLink>
            </div>
            <div className="views">
              <RouterView router={router}></RouterView>
            </div>
          </div>
        </div> 
  );
}
export default connect(state => state,action.administratorActions)(withRouter(App));
